package com.xinyue.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.xinyue.model.user;


public class userDaoImpl extends BaseDao implements userDao{

	
	ResultSet rs=null;
	Connection cnt=null;
	PreparedStatement ps=null;
	
	
	@Override
	public ArrayList getList() {
		ArrayList<user> array = new ArrayList<user>();
		String sql="select * from user_text";//查询表全部信息
		//初始化 数组 ，避免空指针
		Object[] params={};
		rs=this.ExecuteQuery(sql, params);
		
		//在控制台输出 rs的结果集
		try {
			while(rs.next()){
				user si = new user();
				si.setId(rs.getInt(1));
				si.setPass(rs.getString(2));
				si.setName(rs.getString(3));
				si.setHead(rs.getString(4));
				si.setHeadborder(rs.getString(5));
				si.setBornlocal(rs.getString(6));
				si.setNowlocal(rs.getString(7));
				si.setMysign(rs.getString(8));
				si.setMystyle(rs.getString(9));
				si.setLevel(rs.getFloat(10));
				si.setSex(rs.getString(11));
				si.setAge(rs.getInt(12));
				si.setBorntime(rs.getString(13));
				si.setSigntime(rs.getString(14));
				si.setPhone(rs.getString(15));
				si.setEmail(rs.getString(16));
				si.setVip(rs.getString(17));
				si.setViptime(rs.getString(18));
				si.setLastonline(rs.getString(19));
				array.add(si);
			}
			return array;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			this.closeResource();
		}
		return array;
	}

	@Override
	public void add(int id, String pass, String name, String head, String headborder, String bornlocal, String nowlocal,
			String mysign, String mystyle, float level, String sex, int age, String borntime, String signtime,
			String phone, String email, String vip, String viptime, String lastonline) {
		// TODO Auto-generated method stub
		
		
		String sql="insert into user_text(user_id,user_pass,user_name,user_head,user_headborder,user_bornlocal,user_nowlocal,user_mysign,user_mystyle,user_level,user_sex,user_age,user_borntime,user_signtime,user_phone,user_email,user_vip,user_viptime,user_lastonline) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		Object [] params={id,pass,name,head,headborder,bornlocal,nowlocal,mysign,mystyle,level,sex,age,borntime,signtime,phone,email,vip,viptime,lastonline};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("添加成功");
		}
		
		
	}

	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub
		
		String sql="delete from user_text where user_id=?";
		Object [] params={id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("删除成功");
		}
	}

	@Override
	public void updatePass(int id, String pass) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_pass=? where user_id=?";
		Object [] params={pass,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updateName(int id, String name) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_name=? where user_id=?";
		Object [] params={name,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updateHead(int id, String head) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_head=? where user_id=?";
		Object [] params={head,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updateHeadborder(int id, String headborder) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_headborder=? where user_id=?";
		Object [] params={headborder,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updatebornlocal(int id, String bornlocal) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_bornlocal=? where user_id=?";
		Object [] params={bornlocal,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updatenowlocal(int id, String nowlocal) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_nowlocal=? where user_id=?";
		Object [] params={nowlocal,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updatemysign(int id, String mysign) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_mysign=? where user_id=?";
		Object [] params={mysign,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
		
	}

	@Override
	public void updatesex(int id, String sex) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_sex=? where user_id=?";
		Object [] params={sex,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updateborntime(int id, String borntime) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_borntime=? where user_id=?";
		Object [] params={borntime,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updatevip(int id, String vip) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_vip=? where user_id=?";
		Object [] params={vip,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updateviptime(int id, String viptime) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_viptime=? where user_id=?";
		Object [] params={viptime,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public void updatelastonline(int id, String lastonline) {
		// TODO Auto-generated method stub
		
		String sql="update user_text set user_lastonline=? where user_id=?";
		Object [] params={lastonline,id};
		int i=this.executeUpdate(sql, params);
		if(i>0){
			System.out.println("修改成功");
			
		}
		
	}

	@Override
	public int length() {
		// TODO Auto-generated method stub
		
		String sql = "SELECT * FROM user_text;";
		int i = this.lengthrow(sql);
		System.out.println(i);
		return i;
		
	}

}
